/**
 * Created by Administrator on 15-10-8.
 */
window.onload=function(){
    var id =getUserId();
    var url=getUrl();
    var pager = 1;
    $.jsonp({
        url: 'http://'+url+'/api/sameway/sameway_list',
        data: {userId:id,pager:pager},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {

            //console.log(data);
            $.each(data.arrays,function(index,ele){
                var day=new Date(ele.endTime*1000)-new Date(ele.startTime*1000);
                //var day= parseInt(Math.abs((ele.endTime - ele.startTime))/(1000*60*60*24))+1;
                var day= parseInt(day/(1000*60*60*24))+1;
                var unixTimestamp = new Date(ele.startTime*1000)
                commontime = unixTimestamp.toLocaleString();
                var unixTimestamp = new Date(ele.endTime*1000)
                commonTime = unixTimestamp.toLocaleString();
                var sex="female";
                if(ele.sex==1)
                    sex="male";
                var html=' <a href="wode_tongyou_fabu_detail.html?id='+ele.id+'">' +
                    '<li>' +
                    '<div class="ui-tongyou-list-wrap clearfix"> ' +
                    '<div class="ui-tongyou-list-pic">' +
                    '<img src="'+ele.photo+'" alt="">' +
                    '</div>' +
                    '<div class="ui-tongyou-list-content">' +
                    '<h2>'+ele.goAddress+'，'+ele.targetSpots+'<span class="ui-act-ing">进行中</span></h2>' +
                    '<p>同游日期 :'+getTime(ele.startTime)+'</p>' +
                    '<p><em>共'+day+'</a>天</em></p>' +
                    '</div>' +
                    '</div>' +
                    ' <div class="ui-tongyou-list-info">' +
                    '<ul class="clearfix">' +
                    '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-1">'+ele.lookNumber+'人看过</div>' +
                    '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-2">'+ele.comentNumber+'条评论</div>' +
                    '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-3">'+ele.enterIdsNumber+'人报名</div>' +
                    '</ul>' +
                    ' </div>' +
                    ' </li>' +
                    ' </a> ';
                $("#wdtyfb").append(html);
                if(data.arrays.length<15){
                    $(".load-more").text("");
                    return;
                }
            })
        },
        error: function (xOptions, textStatus) {

        }
    });
    $(".load-more").on("click",function() {
        pager = pager + 1;
        $.jsonp({
            url: 'http://'+url+'/api/sameway/sameway_list',
            data: {userId:id,pager:pager},
            callbackParameter: "callback",
            success: function (data, textStatus, xOptions) {

                //console.log(data);
                $.each(data.arrays,function(index,ele){
                    var day=new Date(ele.endTime*1000)-new Date(ele.startTime*1000);
                    //var day= parseInt(Math.abs((ele.endTime - ele.startTime))/(1000*60*60*24))+1;
                    var day= parseInt(day/(1000*60*60*24))+1;
                    var unixTimestamp = new Date(ele.startTime*1000)
                    commontime = unixTimestamp.toLocaleString();
                    var unixTimestamp = new Date(ele.endTime*1000)
                    commonTime = unixTimestamp.toLocaleString();
                    var sex="female";
                    if(ele.sex==1)
                        sex="male";
                    var html=' <a href="wode_tongyou_fabu_detail.html?id='+ele.id+'">' +
                        '<li>' +
                        '<div class="ui-tongyou-list-wrap clearfix"> ' +
                        '<div class="ui-tongyou-list-pic">' +
                        '<img src="'+ele.photo+'" alt="">' +
                        '</div>' +
                        '<div class="ui-tongyou-list-content">' +
                        '<h2>'+ele.goAddress+'，'+ele.targetSpots+'<span class="ui-act-ing">进行中</span></h2>' +
                        '<p>同游日期 :'+getTime(ele.startTime)+'</p>' +
                        '<p><em>共'+day+'</a>天</em></p>' +
                        '</div>' +
                        '</div>' +
                        ' <div class="ui-tongyou-list-info">' +
                        '<ul class="clearfix">' +
                        '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-1">'+ele.lookNumber+'人看过</div>' +
                        '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-2">'+ele.commentSize+'条评论</div>' +
                        '<div class="ui-tongyou-list-info-item ui-tongyou-list-info-3">'+ele.enterIdsNumber+'人报名</div>' +
                        '</ul>' +
                        ' </div>' +
                        ' </li>' +
                        ' </a> ';
                    $("#wdtyfb").append(html);
                    if(data.arrays.length<15){
                        $(".load-more").text("");
                        return;
                    }
                })
            },
            error: function (xOptions, textStatus) {

            }
        });
    });
    //alert($.getUrlParam("id"));
}
//function onBackKeyDown() {
//    jumpbyback(0,"");
//}
function getTime(t){
    var nt = t*1000;
    var n = new Date(nt);
    return formatDate(n);
}
function formatDate(now)   {
    var   year=now.getFullYear();
    var   month=now.getMonth()+1;
    var   date=now.getDate();
    return   year+"-"+(month>=10?month:"0"+month)+"-"+(date>=10?date:"0"+date);
}